package com.RMP
{
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.utils.*;
    import com.greensock.*;

    public class BookmarksSend extends Sprite
    {
        var fadeSpeed:Number;
        var emailShell:BookmarksEmailShell;
        public var coverSprite:Sprite;
        var coverSpriteTop:Sprite;
        var myRoot:MovieClip;
        var longText:LongText;
        var myLink:BookmarkSaveLink;
        var coverSpriteBot:Sprite;

        public function BookmarksSend(param1:MovieClip, param2:Number) : void
        {
            visible = false;
            alpha = 0;
            myRoot = param1;
            fadeSpeed = param2;
            buildLongTitle();
            emailShell = new BookmarksEmailShell();
            emailShell.alpha = 1;
            addChild(emailShell);
            emailShell.submitBtn.buttonMode = true;
            emailShell.submitBtn.useHandCursor = true;
            emailShell.submitBtn.addEventListener(MouseEvent.CLICK, btnClick, false, 0, true);
            emailShell.submitBtn.addEventListener(MouseEvent.ROLL_OVER, btnRollOver, false, 0, true);
            emailShell.submitBtn.addEventListener(MouseEvent.ROLL_OUT, btnRollOut, false, 0, true);
            emailShell.input1.input.addEventListener(FocusEvent.FOCUS_IN, focusInListener, false, 0, true);
            emailShell.input2.input.addEventListener(FocusEvent.FOCUS_IN, focusInListener, false, 0, true);
            emailShell.input3.input.addEventListener(FocusEvent.FOCUS_IN, focusInListener, false, 0, true);
            emailShell.input4.input.addEventListener(FocusEvent.FOCUS_IN, focusInListener, false, 0, true);
            emailShell.input5.input.addEventListener(FocusEvent.FOCUS_IN, focusInListener, false, 0, true);
            emailShell.input1.input.tabIndex = 1;
            emailShell.input2.input.tabIndex = 2;
            emailShell.input3.input.tabIndex = 3;
            emailShell.input4.input.tabIndex = 4;
            emailShell.input5.input.tabIndex = 5;
            emailShell.input1.input.focusRect = false;
            emailShell.input2.input.focusRect = false;
            emailShell.input3.input.focusRect = false;
            emailShell.input4.input.focusRect = false;
            emailShell.input5.input.focusRect = false;
            buildCoverSprite();
            myRoot.stage.addEventListener(Event.RESIZE, onResizer, false, 0, true);
            doResize();
            return;
        }

        function buildCoverSprite() : void
        {
            myLink = new BookmarkSaveLink();
            myLink.field1.field.text = myRoot.path + "www/#/bookmarks/browse/" + myRoot.myBookmarksID + "/";
            myLink.field1.field.addEventListener(FocusEvent.FOCUS_IN, focusInListener, false, 0, true);
            myLink.saveBtn.buttonMode = true;
            myLink.saveBtn.useHandCursor = true;
            myLink.saveBtn.addEventListener(MouseEvent.CLICK, saveBtnClick, false, 0, true);
            myLink.saveBtn.addEventListener(MouseEvent.ROLL_OVER, saveBtnRollOver, false, 0, true);
            myLink.saveBtn.addEventListener(MouseEvent.ROLL_OUT, saveBtnRollOut, false, 0, true);
            addChild(myLink);
            coverSprite = new Sprite();
            coverSprite.graphics.beginFill(16777215, 1);
            coverSprite.graphics.drawRect(0, 0, 1, 1);
            coverSprite.graphics.endFill();
            coverSprite.buttonMode = true;
            coverSprite.useHandCursor = false;
            coverSprite.alpha = 0;
            coverSprite.visible = false;
            addChild(coverSprite);
            return;
        }

        public function fadeOutShell() : void
        {
            visible = false;
            return;
        }

        function doResize() : void
        {
            if (coverSprite != null)
            {
                coverSprite.x = 0;
                coverSprite.y = Math.round(myRoot.headerH + 2 * (myRoot.unitH + myRoot.gutterH) - 5);
                coverSprite.width = 12 * (myRoot.unitW + myRoot.gutterW);
                coverSprite.height = 4 * (myRoot.unitH + myRoot.gutterH);
            }
            if (longText != null)
            {
                longText.x = Math.round(4 * (myRoot.unitW + myRoot.gutterW));
                longText.y = myRoot.headerH + (myRoot.unitH + myRoot.gutterH) - 4 * myRoot.unitW / 75;
                var _loc_1:* = myRoot.unitW / 75;
                longText.field.scaleY = myRoot.unitW / 75;
                longText.field.scaleX = _loc_1;
            }
            if (emailShell != null)
            {
                emailShell.x = Math.round(4 * (myRoot.unitW + myRoot.gutterW));
                emailShell.y = myRoot.headerH + 2 * (myRoot.unitH + myRoot.gutterH) - 4 * myRoot.unitW / 75;
                var _loc_1:* = myRoot.unitW / 75;
                emailShell.title1.scaleY = myRoot.unitW / 75;
                emailShell.title1.scaleX = _loc_1;
                emailShell.input1.y = Math.round(28 * myRoot.unitW / 75);
                emailShell.input1.width = Math.round(4 * myRoot.unitW + 3 * myRoot.gutterW);
                emailShell.input1.height = Math.round(26 * myRoot.unitW / 75);
                var _loc_1:* = myRoot.unitW / 75;
                emailShell.title2.scaleY = myRoot.unitW / 75;
                emailShell.title2.scaleX = _loc_1;
                emailShell.title2.x = Math.round(336 * myRoot.unitW / 75);
                emailShell.input2.x = Math.round(4 * (myRoot.unitW + myRoot.gutterW));
                emailShell.input2.y = Math.round(28 * myRoot.unitW / 75);
                emailShell.input2.width = Math.round(4 * myRoot.unitW + 3 * myRoot.gutterW);
                emailShell.input2.height = Math.round(26 * myRoot.unitW / 75);
                var _loc_1:* = myRoot.unitW / 75;
                emailShell.title3.scaleY = myRoot.unitW / 75;
                emailShell.title3.scaleX = _loc_1;
                emailShell.title3.y = Math.round(71 * myRoot.unitW / 75);
                emailShell.input3.y = Math.round(99 * myRoot.unitW / 75);
                emailShell.input3.width = Math.round(4 * myRoot.unitW + 3 * myRoot.gutterW);
                emailShell.input3.height = Math.round(26 * myRoot.unitW / 75);
                var _loc_1:* = myRoot.unitW / 75;
                emailShell.title4.scaleY = myRoot.unitW / 75;
                emailShell.title4.scaleX = _loc_1;
                emailShell.title4.x = Math.round(4 * (myRoot.unitW + myRoot.gutterW));
                emailShell.title4.y = Math.round(71 * myRoot.unitW / 75);
                emailShell.input4.x = Math.round(4 * (myRoot.unitW + myRoot.gutterW));
                emailShell.input4.y = Math.round(99 * myRoot.unitW / 75);
                emailShell.input4.width = Math.round(4 * myRoot.unitW + 3 * myRoot.gutterW);
                emailShell.input4.height = Math.round(26 * myRoot.unitW / 75);
                var _loc_1:* = myRoot.unitW / 75;
                emailShell.title5.scaleY = myRoot.unitW / 75;
                emailShell.title5.scaleX = _loc_1;
                emailShell.title5.y = Math.round(142 * myRoot.unitW / 75);
                emailShell.input5.y = Math.round(170 * myRoot.unitW / 75);
                emailShell.input5.width = Math.round(4 * myRoot.unitW + 3 * myRoot.gutterW);
                emailShell.input5.height = Math.round(329 * myRoot.unitW / 75);
                var _loc_1:* = Math.round(51 * myRoot.unitW / 75);
                emailShell.submitBtn.width = Math.round(51 * myRoot.unitW / 75);
                emailShell.submitBG.width = _loc_1;
                var _loc_1:* = Math.round(26 * myRoot.unitW / 75);
                emailShell.submitBtn.height = Math.round(26 * myRoot.unitW / 75);
                emailShell.submitBG.height = _loc_1;
                var _loc_1:* = Math.round(4 * (myRoot.unitW + myRoot.gutterW));
                emailShell.submitBtn.x = Math.round(4 * (myRoot.unitW + myRoot.gutterW));
                emailShell.submitBG.x = _loc_1;
                var _loc_1:* = Math.round(170 * myRoot.unitW / 75);
                emailShell.submitBtn.y = Math.round(170 * myRoot.unitW / 75);
                emailShell.submitBG.y = _loc_1;
                emailShell.mySubmit.x = Math.round(338 * myRoot.unitW / 75);
                emailShell.mySubmit.y = Math.round((emailShell.submitBG.y + 1));
                var _loc_1:* = myRoot.unitW / 75;
                emailShell.mySubmit.scaleY = myRoot.unitW / 75;
                emailShell.mySubmit.scaleX = _loc_1;
                emailShell.myArrow.x = Math.round(emailShell.submitBG.x + emailShell.submitBG.width - 10 * myRoot.unitW / 75);
                emailShell.myArrow.y = Math.round(emailShell.submitBG.y + 10 * myRoot.unitW / 75);
                emailShell.msgField.x = emailShell.submitBG.x;
                emailShell.msgField.y = Math.round(emailShell.submitBG.y + emailShell.submitBG.height + 13 * myRoot.unitW / 75);
            }
            if (myLink != null)
            {
                var _loc_1:* = myRoot.unitW / 75;
                myLink.field1.field.scaleY = myRoot.unitW / 75;
                myLink.field1.field.scaleX = _loc_1;
                myLink.field1.inputBG.width = Math.round(6 * myRoot.unitW + 5 * myRoot.gutterW);
                myLink.field1.inputBG.height = Math.round(26 * myRoot.unitW / 75);
                var _loc_1:* = Math.round(6 * (myRoot.unitW + myRoot.gutterW));
                myLink.saveBtn.x = Math.round(6 * (myRoot.unitW + myRoot.gutterW));
                myLink.saveBG.x = _loc_1;
                var _loc_1:* = Math.round(myLink.field1.y);
                myLink.saveBtn.y = Math.round(myLink.field1.y);
                myLink.saveBG.y = _loc_1;
                var _loc_1:* = Math.round(80 * myRoot.unitW / 75);
                myLink.saveBtn.width = Math.round(80 * myRoot.unitW / 75);
                myLink.saveBG.width = _loc_1;
                var _loc_1:* = Math.round(26 * myRoot.unitW / 75);
                myLink.saveBtn.height = Math.round(26 * myRoot.unitW / 75);
                myLink.saveBG.height = _loc_1;
                myLink.mySave.x = myLink.saveBG.x + 3;
                myLink.mySave.y = myLink.saveBG.y + 1;
                var _loc_1:* = myRoot.unitW / 75;
                myLink.mySave.scaleY = myRoot.unitW / 75;
                myLink.mySave.scaleX = _loc_1;
                myLink.saveArrow.x = Math.round(myLink.saveBG.x + myLink.saveBG.width - 10 * myRoot.unitW / 75);
                myLink.saveArrow.y = Math.round(myLink.saveBG.y + 10 * myRoot.unitW / 75);
                myLink.x = Math.round(4 * (myRoot.unitW + myRoot.gutterW));
                myLink.y = Math.round(myRoot.headerH + 2 * myRoot.unitH + myRoot.gutterH - 8 * myRoot.unitW / 75 - myLink.height);
            }
            return;
        }

        function saveBtnClick(event:MouseEvent)
        {
            myRoot.bookmarkLightbox();
            return;
        }

        function sendData() : void
        {
            var _loc_1:* = undefined;
            var _loc_2:* = undefined;
            var _loc_3:* = undefined;
            var _loc_4:* = undefined;
            var _loc_5:* = undefined;
            var _loc_6:String = null;
            var _loc_7:URLVariables = null;
            var _loc_8:URLRequest = null;
            var _loc_9:URLLoader = null;
            _loc_1 = emailShell.input1.input;
            _loc_2 = emailShell.input2.input;
            _loc_3 = emailShell.input3.input;
            _loc_4 = emailShell.input4.input;
            _loc_5 = emailShell.input5.input;
            if (_loc_1.text == " " || _loc_1.text == "" || _loc_2.text == "" || _loc_2.text == " " || _loc_3.text == "" || _loc_3.text == " " || _loc_4.text == "" || _loc_4.text == " ")
            {
                emailShell.msgField.text = "Please complete all fields and resend.";
            }
            else
            {
                emailShell.msgField.text = "Sending email...";
                _loc_6 = myRoot.path + "/lightbox_support/sendLightboxURL.php";
                _loc_7 = new URLVariables();
                _loc_7.lightbox_id = myRoot.myBookmarksID;
                _loc_7.sender = _loc_1.text;
                _loc_7.semail = _loc_2.text;
                _loc_7.recip = _loc_3.text;
                _loc_7.remail = _loc_4.text;
                _loc_7.message = _loc_5.text;
                _loc_8 = new URLRequest(_loc_6);
                _loc_8.data = _loc_7;
                _loc_8.method = URLRequestMethod.POST;
                _loc_9 = new URLLoader();
                _loc_9.dataFormat = URLLoaderDataFormat.TEXT;
                _loc_9.addEventListener(Event.COMPLETE, sendComplete);
                _loc_9.addEventListener(IOErrorEvent.IO_ERROR, sendIOError);
                _loc_9.load(_loc_8);
            }
            return;
        }

        function onResizer(event:Event)
        {
            doResize();
            return;
        }

        function buildLongTitle() : void
        {
            var _loc_1:String = null;
            _loc_1 = "<span class=\'myBold\'>Bookmark Set #" + myRoot.myBookmarksID + "</span><br>Created " + myRoot.bookmarksXML.@date;
            longText = new LongText(myRoot, _loc_1);
            longText.alpha = 1;
            addChild(longText);
            doResize();
            return;
        }

        function btnRollOver(event:MouseEvent)
        {
            TweenMax.to(emailShell.submitBG, fadeSpeed, {tint:myRoot.hotColor, overwrite:true});
            return;
        }

        function btnRollOut(event:MouseEvent)
        {
            TweenMax.to(emailShell.submitBG, fadeSpeed, {tint:myRoot.coldColor, overwrite:true});
            return;
        }

        function saveBtnRollOver(event:MouseEvent)
        {
            TweenMax.to(myLink.saveBG, fadeSpeed, {tint:myRoot.hotColor, overwrite:true});
            return;
        }

        function clearForm() : void
        {
            var _loc_1:* = undefined;
            var _loc_2:* = undefined;
            var _loc_3:* = undefined;
            var _loc_4:* = undefined;
            var _loc_5:* = undefined;
            _loc_1 = emailShell.input1.input;
            _loc_2 = emailShell.input2.input;
            _loc_3 = emailShell.input3.input;
            _loc_4 = emailShell.input4.input;
            _loc_5 = emailShell.input5.input;
            _loc_1.text = "";
            _loc_2.text = "";
            _loc_3.text = "";
            _loc_4.text = "";
            _loc_5.text = "";
            emailShell.msgField.text = "";
            return;
        }

        function btnClick(event:MouseEvent)
        {
            sendData();
            return;
        }

        function sendComplete(event:Event) : void
        {
            var _loc_2:URLVariables = null;
            _loc_2 = new URLVariables(event.target.data);
            if (_loc_2.result == 0)
            {
                emailShell.msgField.text = "Please complete all fields and resend.";
            }
            else if (_loc_2.result == 1)
            {
                emailShell.msgField.text = "Your email has been sent!";
                setTimeout(clearForm, 1000);
            }
            else if (_loc_2.result == 2)
            {
                emailShell.msgField.text = "Please complete all fields and resend.";
            }
            return;
        }

        public function fadeInShell() : void
        {
            visible = true;
            return;
        }

        function focusInListener(event:FocusEvent) : void
        {
            if (stage.displayState == StageDisplayState.FULL_SCREEN)
            {
                myRoot.closeFullscreen();
            }
            return;
        }

        function saveBtnRollOut(event:MouseEvent)
        {
            TweenMax.to(myLink.saveBG, fadeSpeed, {tint:myRoot.coldColor, overwrite:true});
            return;
        }

        function sendIOError(event:IOErrorEvent) : void
        {
            emailShell.msgField.text = "Please complete all fields and resend.";
            return;
        }

    }
}
